var sentlog = sentlog || {referrer:false};
var site_name = site_name || '58';
var page_type = page_type || 'NA';
var post_count = post_count || -1;
var tgreg = tgreg || -1;
var _trackURL = _trackURL || 'NA';
var referrer = encodeURIComponent(document.referrer);
if (!sentlog.referrer) {
	var logmsg = "referrer="+referrer+"&type="+page_type+"&post_count="+post_count;
	if (page_type=='detail') {
		try{
			logmsg = logmsg + '&userid='+____json4fe.userid;
			ajaxsend(document.location.protocol+"//jst2.58.com/?rand="+Math.random()+"&content="
				+encodeURIComponent('[{"userid":"'+____json4fe.userid+'"}]')+"&key="+encodeURIComponent(document.location));
			if ('phone' in ____json4fe) logmsg = logmsg + '&huzhuan='+____json4fe.phone;
			if (tgreg > 0) logmsg = logmsg + '&tgreg='+tgreg;
		}catch(e){}
	}
	try{
		if ('version' in ____json4fe) logmsg = logmsg + '&version='+____json4fe.version;
		if ('start' in ____json4fe) logmsg += '&loadtime='+((new Date()).getTime()-____json4fe.start);
		if ('supplycount' in ____json4fe){
			for(var attr in ____json4fe.supplycount){
				logmsg = logmsg + '&supplycount.'+attr+'='+____json4fe.supplycount[attr];
			}
		}
	}catch(e){}
        try{logmsg = logmsg + '&window_size='+document.documentElement.clientWidth+'x'+document.documentElement.clientHeight;}catch(e){}
	if (_trackURL != 'NA') logmsg = logmsg + '&trackURL='+_trackURL;
	ajaxlog(logmsg);
	try{
		if(typeof(jQuery) != "undefined"){
			var is_postpage_afc_abtest = '';
			if(typeof(postpage_afc_abtest) != 'undefined') is_postpage_afc_abtest = postpage_afc_abtest;
			if(typeof(GoogleAfc) != 'undefined' && GoogleAfc.hasOwnProperty('bottomID') && GoogleAfc.hasOwnProperty('rightID')){
				var llpa = 2; var rlpa = 2;
				var lggad = 1; var rggad = 1;
				var lct = 0; var rct = 0;
				var google_index = "/aclk?";
				var baidu_index_afs = "www.baidu.com/baidu.php?";
				var baidu_index_afc = "www.baidu.com/cpro.php?";
				if(GoogleAfc.hasOwnProperty('bottom_adtype') && GoogleAfc.bottom_adtype == '1'){llpa = 3; lggad = 0;}
				if(GoogleAfc.hasOwnProperty('right_adtype') && GoogleAfc.right_adtype == '1'){rlpa = 3; rggad = 0;}
				jQuery("#" + GoogleAfc.bottomID).find('a').each(function(){if(jQuery(this).attr('href').indexOf(google_index) > 0 || jQuery(this).attr('href').indexOf(baidu_index_afs) > 0 || jQuery(this).attr('href').indexOf(baidu_index_afc) > 0){lct = lct + 1;}});
				jQuery("#" + GoogleAfc.rightID).find('a').each(function(){if(jQuery(this).attr('href').indexOf(google_index) > 0 || jQuery(this).attr('href').indexOf(baidu_index_afs) > 0 || jQuery(this).attr('href').indexOf(baidu_index_afc) > 0){rct = rct + 1;}});
				lct = Math.ceil(lct / llpa);
				rct = Math.ceil(rct / rlpa);
				var lidx = 0; var ridx = 0;
				jQuery("#" + GoogleAfc.bottomID).find('a').each(function(){
					if(jQuery(this).attr('href').indexOf(google_index) > 0 || jQuery(this).attr('href').indexOf(baidu_index_afs) > 0 || jQuery(this).attr('href').indexOf(baidu_index_afc) > 0){
						var curr_idx = lidx;
						var tmp_logtxt = 'pos=bottom&bottom=' + lct + '&right=' + rct + '&click=' + (Math.floor(curr_idx / llpa) + 1) + '&click2=' + curr_idx % llpa + '&isggad=' + lggad;
						if(is_postpage_afc_abtest != '') tmp_logtxt += '&abtest=' + is_postpage_afc_abtest;
						jQuery(this).bind('click', function(){ajaxlog(tmp_logtxt);});
						lidx += 1;
					}
				});
				jQuery("#" + GoogleAfc.rightID).find('a').each(function(){
					if(jQuery(this).attr('href').indexOf(google_index) > 0 || jQuery(this).attr('href').indexOf(baidu_index_afs) > 0 || jQuery(this).attr('href').indexOf(baidu_index_afc) > 0){
						var curr_idx = ridx;
						var tmp_logtxt = 'pos=right&bottom=' + lct + '&right=' + rct + '&click=' + (Math.floor(curr_idx / rlpa) + 1) + '&click2=' + curr_idx % rlpa + '&isggad=' + rggad;
						if(is_postpage_afc_abtest != '') tmp_logtxt += '&abtest=' + is_postpage_afc_abtest;
						jQuery(this).bind('click', function(){ajaxlog(tmp_logtxt);});
						ridx += 1;
					}
				});
			}

			try{
				var trackcities = ['bj', 'sh', 'gz'];
				var trackcates = ['yewu', 'kefu', 'renli', 'caiwu', 'wenziluru', 'cangku'];
				var trackresult = [];
				var loctmp = document.location.href.split('?')[0];
				var citytmp = loctmp.split('.58.com')[0].split('://')[1];
				var catetmps = loctmp.split('.58.com/')[1].split('/');
				var pagetmp = 1;
				try{pagetmp = parseInt(loctmp.split('/pn')[1].split('/')[0]);}catch(pi_e){pagetmp = 1;}
				if(page_type == 'list' && (pagetmp == 0 || pagetmp == 1)){
					for(var idx in catetmps){
						var catetmp = catetmps[idx];
						if(catetmp != '' && trackcates.indexOf(catetmp) > -1 && trackcities.indexOf(citytmp) > -1){
							jQuery('#infolist').find('table').each(function(){
								jQuery(this).find('tr').each(function(i, obj){
									jQuery(obj).find('a').each(function(){
										var hreftmp = jQuery(this).attr('href');
										if(hreftmp.indexOf('x.shtml') > 0){
											var hreftmppart = hreftmp.split('?')[0].split('x.shtml')[0].split('/');
											var infoidtmp = hreftmppart[hreftmppart.length - 1];
											trackresult.push(infoidtmp + '_' + (i + 1));
											return false;
										}
									});
								});
							});
							ajaxlog('titlequality=1&ids=' + trackresult.join(','));
							break;
						}
					}
				}
			}catch(intr_e){}
		}
	}catch(clk_e){}
	sentlog.referrer = true;
}
function setcookie(name,val,days){
	var exp = new Date();
	exp.setTime(exp.getTime() + days*86400000);
	document.cookie = name + '=' + escape(val) + ';expires=' + exp.toGMTString();
}
function getcookie(name){
	var arr, reg=new RegExp("(^| )" + cookie_name + "=([^;]*)(;|$)");
	if(arr = document.cookie.match(reg)){
		return unescape(arr[2]);
	}
	return null;
}
function ajaxsend(url){
	var img = new Image();
	img.src = url;
}
function ajaxlog(log){
	ajaxsend(document.location.protocol+"//track.58.com/empty.js.gif?site_name="+site_name+"&"+log+"&rand="+Math.random());
}

function ajaxlog2(log){
	ajaxlog(log);
}

function ajaxlogr(log){
	ajaxsend(document.location.protocol+"//track.58.com/adsys/listclicklog?site_name="+site_name+"&"+log+"&rand="+Math.random());
}


